package com.maruti.otterapi.searchhistogram;

import com.maruti.otterapi.Otter4JavaException;
import com.maruti.otterapi.TopsyConfig;
import com.maruti.otterapi.TopsyConstants;
import com.maruti.otterapi.TopsyInvoker;
import com.maruti.otterapi.authorinfo.AuthorInfoResponse;

public class SearchHistogram {

	private TopsyConfig topsyConfig;

	public TopsyConfig getTopsyConfig() {
		return topsyConfig;
	}

	public void setTopsyConfig(TopsyConfig topsyConfig) {
		this.topsyConfig = topsyConfig;
	}

	public SearchHistogramResponse searchHistogram(String query)
			throws Otter4JavaException {
		return searchHistogram(query, null, null, null);
	}

	public SearchHistogramResponse searchHistogram(String query, String slice)
			throws Otter4JavaException {
		return searchHistogram(query, slice, null, null);
	}

	public SearchHistogramResponse searchHistogram(String query, String slice,
			String period) throws Otter4JavaException {
		return searchHistogram(query, slice, period, null);
	}

	public SearchHistogramResponse searchHistogram(String query, String slice,
			String period, String count_method) throws Otter4JavaException {

		TopsyInvoker invoker = new TopsyInvoker();
		invoker.setTopsyConfig(topsyConfig);
		query = query.replaceAll("\\s", "%20");
		String params = query;

		if (slice != null)
			params += "&slice=" + slice;

		if (period != null)
			params += "&period=" + period;

		if (count_method != null)
			params += "&count_method="+ count_method;

		SearchHistogramResponse response = null;

		response = (SearchHistogramResponse) invoker.fetchData(
				TopsyConstants.searchHistogramURL + params, "searchHistogram");

		return response;
	}
}
